function outLocations = visStencil(vstencil, dx, idx)
%VISSTENCIL Summary of this function goes here
%   Detailed explanation goes here    
    % 1. find the item. 
    D = numel(dx);
    indices = [vstencil.idx];
    indices = reshape(indices, [D numel(vstencil)]);
    indices(1,:) = indices(1,:) + indices(2,:) * 1024;
    kw = idx(1) + idx(2) * 1024;
    if D >= 3
        indices(1,:) = indices(1,:) + indices(3,:) * (1024.^2);
        kw = kw + idx(3) * (1024.^2);
    end
    jdx = find(indices(1,:) == kw);
    if isempty(jdx)
        disp('No item found for the designated index. ');
        return;
    end
    outLocations = vstencil(jdx(1)).locations;
    % 2. plot the stencil.
    disp(outLocations);
%     if D >= 3
%         return;
%     end
    hold on;
    locations = (outLocations + 0.5) .* reshape(dx, [D 1]);
    if D == 2
        plot(locations(1,:), locations(2,:), 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'k');
    elseif D == 3
        plot3(locations(1,:), locations(2,:), locations(3,:), 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'k');
    end
    q = (reshape(idx, [D 1]) + 0.5) .* reshape(dx, [D 1]);
    if D == 2
        plot(q(1), q(2), 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'w');
    elseif D == 3
        plot3(q(1), q(2), q(3), 'ko', 'MarkerSize', 10, 'MarkerFaceColor', 'w');
    end
end
